/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recontec.Classes;

import utilities.MysqlConnect;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.sql.*;
import javax.swing.table.DefaultTableModel;
import utilities.Data;

/**
 *
 * @author Baltieri
 */
public final class Funcionario extends javax.swing.JFrame {
    
     MysqlConnect objcon;
     Data mostra_data;
     Login obj_usuario;
     int btcon;
     String conbt;
     int btcon1;
     String conbt1;
     
   
   
   
     
////
    /**
     * Creates new form CadastroUsuario
     */
    public Funcionario() {
        
        initComponents();
        
        mostra_data = new Data();
        mostra_data.le_data();
        label_data.setText(mostra_data.dia_semana+", "+mostra_data.dia+" de "+mostra_data.mes+" de "+mostra_data.ano);
        timer1.start();
        obj_usuario = new Login();
        obj_usuario.le_usuario();
       label_usuario.setText("Administrador"+obj_usuario.user);
 ///////////////////////////////////////////////////////////////////////////////
       
       
       
       objcon= new MysqlConnect();
        
        objcon.conecta();
        objcon.executeSQL("select * from setor");
        try{
            while (objcon.resultset.next()) {
                
               // cb_cb.addItem(con_setor.resultset.getString("setor.DescricaoSetor"));
                // cb_cb.addItem(objcon.resultset.getString("DescricaoSetor"));
            }
        
        } catch (SQLException sql)
        
        {
            JOptionPane.showMessageDialog(null, "sql erro ConboBOx");
        }
      
       objcon.executeSQL("select * from Cargo");
       
        try{
            while (objcon.resultset.next()) {
                cb_cargo.addItem(objcon.resultset.getString("DescricaoCargo"));
            }
        
        } catch (SQLException sql)
        
        {
            JOptionPane.showMessageDialog(null, "sql erro CongoBOx");
           
       
       
 ///////////////////////////////////////////////////////////////////////////////
        
        
        
        
        
        
        btcon=0;
        btcon1=0; 
        btIncluir.setEnabled(false);
        objcon = new MysqlConnect();
      
        
        objcon.conecta();
        objcon.executeSQL("select * from setor");
         AlimentarTable();
        try{
           objcon.resultset.first();
           tfCod.setText(objcon.resultset.getString("DescricaoSetor"));
           nome_func.setText(objcon.resultset.getString("nome"));
           tfUsername.setText(objcon.resultset.getString("endereco"));
           tfTelefone.setText(objcon.resultset.getString("Telefone"));
           tfConfirmPassword.setText(objcon.resultset.getString("Confirm"));
    
              
        }catch(SQLException Error)
        {
           JOptionPane.showMessageDialog(null,"Dados não encontrados"); 
        }
       
       
        }
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        timer1 = new org.netbeans.examples.lib.timerbean.Timer();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btFirst = new javax.swing.JButton();
        btPrevious = new javax.swing.JButton();
        btNext = new javax.swing.JButton();
        btLast = new javax.swing.JButton();
        btIncluir = new javax.swing.JButton();
        btLimparDados = new javax.swing.JButton();
        btRemover = new javax.swing.JButton();
        btAlterar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        tfCod = new javax.swing.JTextField();
        nome_func = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfUsername = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tfTelefone = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tfConfirmPassword = new javax.swing.JTextField();
        tfConsultar = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        label_usuario = new javax.swing.JLabel();
        label_hora = new javax.swing.JLabel();
        label_data = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        tfEmail = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cb_cargo = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();

        timer1.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer1OnTime(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1024, 768));
        setPreferredSize(new java.awt.Dimension(1024, 768));
        getContentPane().setLayout(null);
        getContentPane().add(jLabel1);
        jLabel1.setBounds(6, 555, 256, 0);

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Funcionário");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(31, 37, 210, 47);

        btFirst.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/Top-48.png"))); // NOI18N
        btFirst.setToolTipText("Primeiro registro");
        btFirst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btFirstActionPerformed(evt);
            }
        });
        btFirst.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                btFirstFocusGained(evt);
            }
        });
        getContentPane().add(btFirst);
        btFirst.setBounds(350, 400, 65, 41);

        btPrevious.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/player_rew-48.png"))); // NOI18N
        btPrevious.setToolTipText("Registro anterior");
        btPrevious.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPreviousActionPerformed(evt);
            }
        });
        btPrevious.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                btPreviousFocusGained(evt);
            }
        });
        getContentPane().add(btPrevious);
        btPrevious.setBounds(410, 400, 65, 41);

        btNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/player_fwd-48.png"))); // NOI18N
        btNext.setToolTipText("Próximo registro");
        btNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNextActionPerformed(evt);
            }
        });
        btNext.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                btNextFocusGained(evt);
            }
        });
        getContentPane().add(btNext);
        btNext.setBounds(460, 400, 65, 41);

        btLast.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/player_end-48.png"))); // NOI18N
        btLast.setToolTipText("Ultimo registro");
        btLast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLastActionPerformed(evt);
            }
        });
        btLast.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                btLastFocusGained(evt);
            }
        });
        getContentPane().add(btLast);
        btLast.setBounds(510, 400, 65, 41);

        btIncluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/filesaveas-48.png"))); // NOI18N
        btIncluir.setToolTipText("Salvar registro");
        btIncluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btIncluirActionPerformed(evt);
            }
        });
        getContentPane().add(btIncluir);
        btIncluir.setBounds(570, 400, 65, 41);

        btLimparDados.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/filenew-48.png"))); // NOI18N
        btLimparDados.setToolTipText("Novo registro");
        btLimparDados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLimparDadosActionPerformed(evt);
            }
        });
        btLimparDados.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                btLimparDadosFocusLost(evt);
            }
        });
        getContentPane().add(btLimparDados);
        btLimparDados.setBounds(620, 400, 65, 41);

        btRemover.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/button_cancel-48.png"))); // NOI18N
        btRemover.setToolTipText("Excluir registro");
        btRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoverActionPerformed(evt);
            }
        });
        getContentPane().add(btRemover);
        btRemover.setBounds(680, 400, 65, 41);

        btAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/edit-48-1.png"))); // NOI18N
        btAlterar.setToolTipText("Editar registro");
        btAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAlterarActionPerformed(evt);
            }
        });
        getContentPane().add(btAlterar);
        btAlterar.setBounds(730, 400, 65, 41);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Cod", "Nome", "Endereço", "Telefone", "Email"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(90, 460, 860, 230);

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/Gold-ACD-256.png"))); // NOI18N
        getContentPane().add(jLabel7);
        jLabel7.setBounds(30, 160, 267, 203);

        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Código:");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(350, 120, 60, 14);

        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("Nome:");
        getContentPane().add(jLabel14);
        jLabel14.setBounds(430, 120, 60, 14);

        tfCod.setEditable(false);
        tfCod.setEnabled(false);
        getContentPane().add(tfCod);
        tfCod.setBounds(350, 140, 75, 30);

        nome_func.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nome_funcActionPerformed(evt);
            }
        });
        nome_func.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                nome_funcFocusLost(evt);
            }
        });
        getContentPane().add(nome_func);
        nome_func.setBounds(430, 140, 350, 30);

        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Nome de usuário:");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(350, 180, 140, 14);

        tfUsername.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfUsernameActionPerformed(evt);
            }
        });
        tfUsername.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfUsernameFocusGained(evt);
            }
        });
        getContentPane().add(tfUsername);
        tfUsername.setBounds(350, 200, 220, 30);

        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Senha:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(570, 180, 70, 14);

        tfTelefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfTelefoneActionPerformed(evt);
            }
        });
        getContentPane().add(tfTelefone);
        tfTelefone.setBounds(570, 200, 210, 30);

        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Confirmar senha:");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(350, 240, 140, 14);

        tfConfirmPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfConfirmPasswordActionPerformed(evt);
            }
        });
        getContentPane().add(tfConfirmPassword);
        tfConfirmPassword.setBounds(350, 260, 220, 30);

        tfConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfConsultarActionPerformed(evt);
            }
        });
        getContentPane().add(tfConsultar);
        tfConsultar.setBounds(780, 90, 165, 30);

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/search-32.png"))); // NOI18N
        getContentPane().add(jLabel8);
        jLabel8.setBounds(950, 86, 30, 30);

        label_usuario.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        label_usuario.setForeground(new java.awt.Color(255, 255, 255));
        label_usuario.setText("Usuário");
        label_usuario.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        getContentPane().add(label_usuario);
        label_usuario.setBounds(830, 10, 130, 30);

        label_hora.setFont(new java.awt.Font("Lucida Sans", 0, 16)); // NOI18N
        label_hora.setForeground(new java.awt.Color(255, 255, 255));
        label_hora.setText("Horas");
        getContentPane().add(label_hora);
        label_hora.setBounds(880, 40, 110, 20);

        label_data.setFont(new java.awt.Font("Lucida Grande", 2, 24)); // NOI18N
        label_data.setForeground(new java.awt.Color(255, 255, 255));
        label_data.setText("Data");
        getContentPane().add(label_data);
        label_data.setBounds(60, 710, 680, 40);

        jLabel13.setFont(new java.awt.Font("Times New Roman", 0, 24)); // NOI18N
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("*");
        getContentPane().add(jLabel13);
        jLabel13.setBounds(780, 270, 12, 28);

        jLabel15.setFont(new java.awt.Font("Times New Roman", 0, 24)); // NOI18N
        jLabel15.setForeground(new java.awt.Color(255, 255, 255));
        jLabel15.setText("*");
        getContentPane().add(jLabel15);
        jLabel15.setBounds(780, 170, 12, 28);

        jLabel16.setFont(new java.awt.Font("Times New Roman", 0, 24)); // NOI18N
        jLabel16.setForeground(new java.awt.Color(255, 255, 255));
        jLabel16.setText("*");
        getContentPane().add(jLabel16);
        jLabel16.setBounds(780, 220, 12, 28);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/3D-Home-32.png"))); // NOI18N
        jButton1.setToolTipText("Menu Principal");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(970, 10, 40, 40);
        getContentPane().add(tfEmail);
        tfEmail.setBounds(570, 260, 230, 30);

        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Email:");
        getContentPane().add(jLabel10);
        jLabel10.setBounds(570, 240, 40, 14);

        getContentPane().add(cb_cargo);
        cb_cargo.setBounds(710, 320, 210, 20);

        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Setor");
        getContentPane().add(jLabel11);
        jLabel11.setBounds(350, 300, 26, 14);

        jLabel12.setForeground(new java.awt.Color(255, 255, 255));
        jLabel12.setText("Cargo");
        getContentPane().add(jLabel12);
        jLabel12.setBounds(710, 300, 29, 14);

        jRadioButton1.setForeground(new java.awt.Color(255, 255, 255));
        jRadioButton1.setText("Operacional");
        jRadioButton1.setFocusPainted(false);
        jRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButton1MouseClicked(evt);
            }
        });
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });
        jRadioButton1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jRadioButton1PropertyChange(evt);
            }
        });
        getContentPane().add(jRadioButton1);
        jRadioButton1.setBounds(350, 320, 82, 22);

        jRadioButton2.setForeground(new java.awt.Color(255, 255, 255));
        jRadioButton2.setText("Administracao");
        jRadioButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButton2MouseClicked(evt);
            }
        });
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });
        jRadioButton2.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jRadioButton2PropertyChange(evt);
            }
        });
        getContentPane().add(jRadioButton2);
        jRadioButton2.setBounds(450, 320, 93, 23);

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recontec/background.jpg"))); // NOI18N
        getContentPane().add(jLabel9);
        jLabel9.setBounds(0, 0, 1050, 790);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tfTelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfTelefoneActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfTelefoneActionPerformed

    private void btFirstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFirstActionPerformed
        // TODO add your handling code here:
       try{
           objcon.resultset.first();
           Exibir();
       }catch(SQLException Error){
           JOptionPane.showMessageDialog(null,"Esse é o ultimo registro");
       }
       
       
    }//GEN-LAST:event_btFirstActionPerformed

    private void btPreviousActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPreviousActionPerformed
        // TODO add your handling code here:
        try{
           
           objcon.resultset.previous();
           Exibir();
       }catch(SQLException Error){
           JOptionPane.showMessageDialog(null,"Aki Esse é o primeiro registro");
       }
    }//GEN-LAST:event_btPreviousActionPerformed

    private void btNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNextActionPerformed
        // TODO add your handling code here:
        try{
           objcon.resultset.next();
           Exibir();
       }catch(SQLException Error){
           JOptionPane.showMessageDialog(null,"Esse é o ultimo registro");
       }
    }//GEN-LAST:event_btNextActionPerformed

    private void btLastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLastActionPerformed
        // TODO add your handling code here:
       try{
           objcon.resultset.last();
           Exibir();
       }catch(SQLException Error){
           JOptionPane.showMessageDialog(null,"Esse é o ultimo registro");
       }
    }//GEN-LAST:event_btLastActionPerformed

    private void btIncluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btIncluirActionPerformed
        // TODO add your handling code here:
        Incluir();
    }//GEN-LAST:event_btIncluirActionPerformed
    
    private void btLimparDadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparDadosActionPerformed
        // TODO add your handling code here:
        LimpaDados();
        btIncluir.setEnabled(true);
        btRemover.setEnabled(false);
        btAlterar.setEnabled(false);
        nome_func.requestFocus();
        
        
    }//GEN-LAST:event_btLimparDadosActionPerformed

    private void btRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoverActionPerformed
        // TODO add your handling code here:
        Remover();
    }//GEN-LAST:event_btRemoverActionPerformed

    private void btAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAlterarActionPerformed
        // TODO add your handling code here:
       alterar();
    }//GEN-LAST:event_btAlterarActionPerformed

    private void tfUsernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfUsernameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfUsernameActionPerformed

    private void tfConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfConsultarActionPerformed
        // TODO add your handling code here:
      Consultar();
    }//GEN-LAST:event_tfConsultarActionPerformed

    private void tfUsernameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfUsernameFocusGained
        // TODO add your handling code here:
   
    }//GEN-LAST:event_tfUsernameFocusGained

    private void btLimparDadosFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_btLimparDadosFocusLost
        // TODO add your handling code here:
        if(btIncluir.requestDefaultFocus()){
            btRemover.setEnabled(false);
        }else{
            btRemover.setEnabled(true);
        }
    }//GEN-LAST:event_btLimparDadosFocusLost

    private void btFirstFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_btFirstFocusGained
        // TODO add your handling code here:
        Buttons();
    }//GEN-LAST:event_btFirstFocusGained

    private void btPreviousFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_btPreviousFocusGained
        // TODO add your handling code here:
        Buttons();
    }//GEN-LAST:event_btPreviousFocusGained

    private void btNextFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_btNextFocusGained
        // TODO add your handling code here:
       Buttons();
    }//GEN-LAST:event_btNextFocusGained

    private void btLastFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_btLastFocusGained
        // TODO add your handling code here:
        Buttons();
    }//GEN-LAST:event_btLastFocusGained

    private void timer1OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer1OnTime
        // TODO add your handling code here:
        mostra_data.le_hora();
        label_hora.setText(mostra_data.hora);
    }//GEN-LAST:event_timer1OnTime

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        
        new Principal().setVisible(true);
                   this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void tfConfirmPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfConfirmPasswordActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfConfirmPasswordActionPerformed

    private void nome_funcFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nome_funcFocusLost
        // TODO add your handling code here:

    }//GEN-LAST:event_nome_funcFocusLost

    private void nome_funcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nome_funcActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nome_funcActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton1MouseClicked
        // TODO add your handling code here:
        btcon =1;
    }//GEN-LAST:event_jRadioButton1MouseClicked

    private void jRadioButton1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jRadioButton1PropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton1PropertyChange

    private void jRadioButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton2MouseClicked
        // TODO add your handling code here:
         btcon=2;
    }//GEN-LAST:event_jRadioButton2MouseClicked

    private void jRadioButton2PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jRadioButton2PropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton2PropertyChange

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Beneficiario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Beneficiario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Beneficiario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Beneficiario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Funcionario().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAlterar;
    private javax.swing.JButton btFirst;
    private javax.swing.JButton btIncluir;
    private javax.swing.JButton btLast;
    private javax.swing.JButton btLimparDados;
    private javax.swing.JButton btNext;
    private javax.swing.JButton btPrevious;
    private javax.swing.JButton btRemover;
    private javax.swing.JComboBox cb_cargo;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel label_data;
    private javax.swing.JLabel label_hora;
    private javax.swing.JLabel label_usuario;
    private javax.swing.JTextField nome_func;
    private javax.swing.JTextField tfCod;
    private javax.swing.JTextField tfConfirmPassword;
    private javax.swing.JTextField tfConsultar;
    private javax.swing.JTextField tfEmail;
    private javax.swing.JTextField tfTelefone;
    private javax.swing.JTextField tfUsername;
    private org.netbeans.examples.lib.timerbean.Timer timer1;
    // End of variables declaration//GEN-END:variables
public void Exibir(){
     try{
           
           tfCod.setText(objcon.resultset.getString("DescricaoSetor"));
           nome_func.setText(objcon.resultset.getString("nome"));
           tfUsername.setText(objcon.resultset.getString("Login"));
           tfTelefone.setText(objcon.resultset.getString("telefone"));
           tfConfirmPassword.setText(objcon.resultset.getString("password"));
    
              
        }catch(SQLException Error)
        {
            if (btPrevious.hasFocus()){
           JOptionPane.showMessageDialog(null,"Este é o primeiro registro"); 
        }else {
              JOptionPane.showMessageDialog(null,"Este é o ultimo registro");  
            }
        }
}
public void LimpaDados(){
    tfCod.setText("");
    tfConfirmPassword.setText("");
    tfUsername.setText("");
    nome_func.setText("");
    tfTelefone.setText("");
}
//Metodo para alimentar o JTable
public void AlimentarTable(){
    jTable1.getColumnModel().getColumn(0).setPreferredWidth(10);
    jTable1.getColumnModel().getColumn(1).setPreferredWidth(20);
    jTable1.getColumnModel().getColumn(2).setPreferredWidth(60);
    jTable1.getColumnModel().getColumn(3).setPreferredWidth(40);
    jTable1.getColumnModel().getColumn(4).setPreferredWidth(40);
    
    DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
    model.setNumRows(0);
    
    try {
        objcon.executeSQL("select * from funcionarios");
        while (objcon.resultset.next()) {
            model.addRow(new Object[]{objcon.resultset.getString("idfuncionarios"),objcon.resultset.getString("nome"),
              objcon.resultset.getString("endereco"),objcon.resultset.getString("telefone"),objcon.resultset.getString("Login"),objcon.resultset.getString("Senha"),
              objcon.resultset.getString("email")});
            
        }
    }catch(SQLException Error){
      JOptionPane.showMessageDialog(null, "Erro ao listar dados no JTable");  
    }
    
    
}
public void Buttons(){
    btIncluir.setEnabled(false);
    btRemover.setEnabled(true);
    btAlterar.setEnabled(true);
    
}

public void Incluir ()
{
    if (nome_func.getText().equals("") || tfUsername.getText().equals("")|| tfTelefone.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Os campos com asterisco (*) são de preenchimento obrigatório !");
        }else{
         try{
            objcon.conecta();
            objcon.statement=objcon.conexao.createStatement();
            String sqlinsert ="insert into Funcionarios (Nome,Endereco,Login,Senha,IdCargo,IdSetor) values ('"+
                    nome_func.getText()+"','"+
                    tfUsername.getText()+"','"+
                    tfConfirmPassword.getText()+"','"+
                    tfEmail.getText()+"','"+
                    btcon+"','"+
                   // cb_cb.getSelectedItem()+"','"+
                    cb_cargo.getSelectedItem()+"')";
            
                    
            
            //JOptionPane.showMessageDialog(null,"sql = "+sqlinsert);
            objcon.statement.executeUpdate(sqlinsert);
            JOptionPane.showMessageDialog(null, "Cadastro realizado com sucesso !");
            //objcon.statement.close();
            
            //resultset update
            //objcon.resultset = objcon.statement.executeQuery("select * from beneficiarios ");
            objcon.executeSQL("select * from Funcionarios");
            objcon.resultset.first();
            Exibir();
            AlimentarTable();
            
                    
        }catch (SQLException erro){
            
        
            JOptionPane.showMessageDialog(null, "Erro ao tentar cadastrar usuario");
        }
    }
}
public void alterar()
{
     if (nome_func.getText().equals("") || tfUsername.getText().equals("")|| tfTelefone.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Os campos com asterisco (*) são de preenchimento obrigatório !");
        }else{
        try{
            String sql = "UPDATE Funcionarios SET nome ='"+nome_func.getText()+"',"+
                    "endereco = '"+tfUsername.getText()+"',telefone = '"+tfTelefone.getText()+"'"+
                    ",email = '"+tfConfirmPassword.getText()+"' where idFuncinarios = '"+
                    tfCod.getText()+"'";
            
            objcon.statement.executeUpdate(sql);
            JOptionPane.showMessageDialog(null, "Alteração realizada com sucesso !");
            
            //ResultSet Update
            objcon.executeSQL("select * from Funcionarios");
            objcon.resultset.first(); // aponta para o primeiro registro no banco
            
            Exibir();//metodo que mostra dados no formulario
           
           
            
        }catch(SQLException Erro){
            JOptionPane.showMessageDialog(null, "Erro ao tentar alterar registro");
        }
         
        }
        AlimentarTable();
        objcon.executeSQL("select * from Funcionarios");
}
public void Remover()
{
    try{
            String sql = "select * from Funcionarios where idFuncionarios="+tfCod.getText();
            objcon.executeSQL(sql);
            objcon.resultset.first();
            String nome = "Deletar o Funcionarios : "+objcon.resultset.getString("nome")+" ?";
            int answer = JOptionPane.showConfirmDialog(null,nome,"REMOVER",JOptionPane.YES_NO_OPTION);
            if (answer==JOptionPane.YES_OPTION){
                sql = "delete from Funcionarios where idFuncionarios="+tfCod.getText();
                int deleteconfirm = objcon.statement.executeUpdate(sql);
                if (deleteconfirm==1){
                    JOptionPane.showMessageDialog(null,"Funcionarios excluido com sucesso");
                    //resultset update
                    objcon.executeSQL("select * from Funcionarios");
                    objcon.resultset.first();
                   Exibir();
                    AlimentarTable();
                }
            }else{
            }
        }catch(SQLException error){
            JOptionPane.showMessageDialog(null, "Erro ao tentar excluir Funcionarios");
        }
        objcon.executeSQL("select * from Funcionarios");
}
public void Consultar()
{
      try{
            objcon.resultset.first();
            String valor = "n";
            int search_length = tfConsultar.getText().length();
            //while ("n".equals(valor)){
            while("n".equals(valor)){
            String procurado = objcon.resultset.getString("Nome").substring(0,(search_length));
            
            if (procurado.equals(tfConsultar.getText())){
                valor = "s";
            }else {
                    objcon.resultset.next();
                }
            
        }
            
           // mostra DataShow();
            tfCod.setText(objcon.resultset.getString("idFuncionarios"));
            Exibir();
        }catch(SQLException Error){
            JOptionPane.showMessageDialog(null, "Erro ao tentar localizar registro !");
        }
}
}


